var url = require('url');
var template = require('templateConfig');
var main = require('main');
var form = require('form');
var module= require("module");

//模板配置
var tplArr = [];
var modalTpl =require('raw!../template/modal.txt'); 
var personalTpl =require('raw!../template/personal-center.txt'); 
var indexTpl =require('raw!../template/personal-index.txt'); 
tplArr['modal'] = template.compile(modalTpl.replace(/^\s*|\s*$/g, "")); 
tplArr['personal'] = template.compile(personalTpl.replace(/^\s*|\s*$/g, "")); 
tplArr['index'] = template.compile(indexTpl.replace(/^\s*|\s*$/g, "")); 
 
 var Ztype = main.GetQueryString('type');
function Index(){
    _this = this;
    this.main = function(){
        main.event(this,'tap','i-click'); 
        this.init();
    }     

    /**
     * @param  {string} page "come from which page"
     * 个人中心首页
     */
    this.getContent= function(page){
        var baseUrl= _this.baseUrl;
        var data= {
            tType: "content"
        };
        var data_body= {
            tType: "contentbody",
        }
        var data1 = {"list":[
                {"name":"门店数","key":"10"},
                {"name":"累计销售额","key":"1000.00"},
                {"name":"累计佣金额","key":"0"},
            ]};
        //个人信息
        var data_headblock= {
            tType: "headblock",
            image: "",
            title: "Golan Yao",
            tag: "虚拟店员",
            content: [{
                key: "加盟商编号",
                value: "123"
            }],
            qrcode: "http://placeholder.qiniudn.com/300x300",
            qrlink: "",
            qrdetail: "扫码成为专享粉丝，享受粉丝福利！"
        };  
        //申请加入说明
        var data_partner= {
            tType: "partner",
            title: "恭喜您！您已成为【超级粉丝】有机会成为【虚拟店员】",
            description: "虚拟店员可获得虚拟店员专享二维码，享有8折拿货。",
            link: "",
            name: "微商申请流程"
        };        
        //超链接列表
        var data_arrlist= {
            tType: "arrlist",
            dataList: [{
                name: "买家中心",
                link: ""
            },{
                name: "卖家中心",
                click: "getContentBody,"+page,
            }]
        };
        main.post(url.clerOpenidkSingle,{},function(res){
            var ret=res.data;
            console.log(ret);

            data_headblock.title=ret.clerk_name;
            data_headblock.content[0].value=ret.clerk_number;
            data_headblock.qrcode=ret.ercode_url;
            if(ret.status==1){
               data1.list[0].key=ret.store_number;
               data1.list[1].key=ret.countprice;
               data1.list[2].key=ret.counts; 
            }

            switch(page){
                case "storepartner":
                //门店合伙人
                data_headblock.tag= "门店合伙人";
                data_headblock.qrdetail= "";
                data_partner.title= "恭喜您！您满足条件，有机会申请成为【管理合伙人】";
                data_partner.description= "管理合伙人可获得品牌大使专享二维码，享有65折拿货。"
                data.headblock= module.getModule(data_headblock, "headblock");
                // data.account= tplArr['personal'](data_account);
                data_body.arrlist= module.getModule(data_arrlist, "arrlist");
                data_body.partner= module.getModule(data_partner, "partner"); 
                break;  

                case "clerkmember":
                //店员
                data_headblock.tag= "普通店员";
                data_headblock.qrdetail= "";
                data.headblock= module.getModule(data_headblock, "headblock"); 
                data_body.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;  

                case "clerkmaster":
                //店长
                data_headblock.tag= "店长";
                data_headblock.qrdetail= "";
                data.headblock= module.getModule(data_headblock, "headblock"); 
                data_body.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;    

                case "alliance":
                //加盟商
                data_headblock.tag= "";
                data_headblock.qrdetail= "";
                data.headblock= module.getModule(data_headblock, "headblock"); 
                data.triple= module.getModule(data1, "InfoTiled");
                data_body.arrlist= module.getModule(data_arrlist, "arrlist");             
                break;          

            } 
            $(".content").html(tplArr['index'](data)); 
            $(".content-body").empty().append(tplArr['index'](data_body));

        });        
        
    }
    //卖家中心
    this.getContentBody= function (ths, page) {
        var baseUrl= _this.baseUrl;
        var data_body= {
            tType: "contentbody",
        }
        //积分
        var data_account= {
            tType: "account",
            key: "当前积分",
            val: "1200",
            name: "去积分商城"
        };
        //超链接列表
        var data_arrlist= {
            tType: "arrlist",
            dataList: [{
                name: "订单管理",
                link: ""
            },{
                name: "粉丝订单", 
                link: ""
            },{
                name: "我的佣金", 
                link: ""
            }]
        };   
        //申请加入说明
        var data_partner= {
            tType: "partner",
            title: "恭喜您！您满足条件，有机会申请成为【管理合伙人】",
            description: "管理合伙人可获得品牌大使专享二维码，享有65折拿货。",
            link: "",
            name: "微商申请流程"
        };                  
        //我的订单
        var data_tabblock= {
            tType: "tabblock",
            title: "我的订单",
            baseUrl: baseUrl,
            dataList: [{
                image: _this.baseUrl+"order_1.jpg",
                name: "全部订单",
                click: "",
                cornernum: ""
            },{
                image: _this.baseUrl+"order_2.jpg",
                name: "待付款",
                click: "",
                cornernum: ""
            },{
                image: _this.baseUrl+"order_3.jpg",
                name: "代收货",
                click: "",
                cornernum: ""
            },{
                image: _this.baseUrl+"order_4.jpg",
                name: "待评价",
                click: "",
                cornernum: ""
            },{
                image: _this.baseUrl+"order_5.jpg",
                name: "退换货",
                click: "",
                cornernum: ""
            }]
        }; 
        main.post(url.clerOpenidkSingle,{},function(res){
            var ret=res.data;
            data_account.val=ret.integral;
            switch(page){
                case "storepartner":
                //门店合伙人
                    data_body.account= module.getModule(data_account, "account");
                    data_body.arrlist= module.getModule(data_arrlist, "arrlist");
                    data_body.partner= module.getModule(data_partner, "partner");
                break;

                case "clerkmember":
                //店员            
                    data_body.account= module.getModule(data_account, "account");
                    data_body.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;  

                case "clerkmaster":
                //店长
                    data_body.arrlist= module.getModule(data_arrlist, "arrlist"); 
                break;  

                case "alliance":
                data_arrlist= {
                tType: "arrlist",
                dataList: [{
                        name: "店员身份审核",
                        link: ""
                    },{
                        name: "门店身份审核", 
                        link: ""
                    },{
                        name: "粉丝迁移设置", 
                        link: ""
                    }]
                };   
                //我的操作
                var data_tabblock= {
                    tType: "tabblock",
                    title: "我的订单",
                    baseUrl: baseUrl,
                    dataList: [{
                        image: _this.baseUrl+"order_1.jpg",
                        name: "全部订单",
                        click: "jump1",
                        cornernum: ""
                    },{
                        image: _this.baseUrl+"order_2.jpg",
                        name: "待付款",
                        click: "jump2",
                        cornernum: ""
                    },{
                        image: _this.baseUrl+"order_3.jpg",
                        name: "代收货",
                        click: "jump3",
                        cornernum: ""
                    },{
                        image: _this.baseUrl+"order_4.jpg",
                        name: "待评价",
                        click: "jump4",
                        cornernum: ""
                    },{
                        image: _this.baseUrl+"order_5.jpg",
                        name: "退换货",
                        click: "jump5",
                        cornernum: ""
                    }]
                }; 
                //加盟商                
                    data_body.tabblock= module.getModule(data_tabblock, "tabblock");
                    data_body.arrlist= module.getModule(data_arrlist, "arrlist"); 
            }        
            $(".content-body").empty().append(tplArr['index'](data_body));
        });
        
    }
    console.log(Ztype);
    this.jump1=function(){
        window.location.href=url.orderManager+'?type='+Ztype;
    }
    this.jump2=function(){
        window.location.href=url.orderManager+'?type='+Ztype+'&order_status=pay_0';
    }
    this.jump3=function(){
        window.location.href=url.orderManager+'?type='+Ztype+'&order_status=shipping_1';
    }
    this.jump4=function(){
        window.location.href=url.orderManager+'?type='+Ztype+'&order_status=assess_1';
    }
    this.jump5=function(){
        window.location.href=url.orderManager+'?type='+Ztype+'&order_status=return_4';
    }
    //inital page
    this.init= function(){ 
        this.page= _page;
        this.baseUrl= url.baseImageUrl;
        this.getContent(this.page);
    }
    return this.main();
};

var index = new Index();